<template>
  <div class="center">
    <h1>登录</h1>
    <div class="login">
      <div :class="overlaylong">
        <div class="overlaylong-Signin" v-if="disfiex == 0">
          <h2 class="overlaylongH2">登录</h2>
          <el-input ref="username" v-model="username" placeholder="请输入用户名"></el-input>
          <el-input ref="password" show-password v-model="password" placeholder="请输入密码"></el-input>
          <!--          <h3>忘记密码</h3>-->
          <button class="inupbutton" @click="handleLogin">登录</button>
        </div>
        <!--        <div class="overlaylong-Signup" v-if="disfiex == 1">-->
        <!--          <h2 class="overlaylongH2">注册账号</h2>-->
        <!--          <el-input ref="username" v-model="username" placeholder="请输入用户名"></el-input>-->
        <!--          <el-input ref="password" show-password v-model="password" placeholder="请输入密码"></el-input>-->
        <!--          <button class="inupbutton" @click="handleSignup">注册</button>-->
        <!--        </div>-->
        <div class="overlaylong-introduce" v-if="disfiex == 1">
          <h2 class="overlaylongH2">公司简介</h2>
          <div class="introduce">
            <p style="color: #263445">
              给我打点钱@中国银行@中国工商银行@招商银行@中国农业银行 @中国建设银行
              @中国民生银行@中信银行@兴业银行@中国人民银行@中国邮政储蓄银行@中国农业发展银行
            </p>
          </div>
        </div>

      </div>
      <div :class="overlaytitle">
        <div class="overlaytitle-Signin" v-if="disfiex == 0">
          <h2 class="overlaytitleH2">欢迎回来！</h2>
          <p class="overlaytitleP">
            与我们一起旅程吧！
          </p>
          <div class="buttongohs" @click="Signin">简介</div>
        </div>
        <div class="overlaytitle-introduce" v-if="disfiex == 1">
          <h2 class="overlaytitleH2">欢迎回来！</h2>
          <p class="overlaytitleP">请使用您的个人信息登录，保持与我们联系！</p>
          <div class="buttongohs" @click="Signup">登录</div>
        </div>
      </div>
    </div>

  </div>
</template>

<script>
import Cookie from "js-cookie";
import {login} from "@/api/User";

export default {
  data() {
    return {
      username: 'admin',
      password: '123456',
      overlaylong: 'overlaylong',
      overlaytitle: 'overlaytitle',
      disfiex: 0
    }
  },
  methods: {
    Signin() {
      this.overlaylong = "overlaylongleft"
      this.overlaytitle = "overlaytitleright"
      this.username = ''
      this.password = ''
      setTimeout(() => {
        this.disfiex = 1
      }, 200)
    },
    Signup() {
      this.overlaylong = "overlaylongright"
      this.overlaytitle = "overlaytitleleft"
      this.username = ''
      this.password = ''
      setTimeout(() => {
        this.disfiex = 0
      }, 200)
    },
    handleLogin() {
      // 1. 获取用户输入的用户名和密码
      const username = this.$refs.username.value;
      const password = this.$refs.password.value;
      if (!username || !password) {
        this.$message.error('请输入用户名和密码!');
        return;
      }
      // 2. 发送登录请求
      login({username, password}).then(response => {
        if (response.data.code === 200) {
          this.$message({
            message: username + ' 登录成功!',
            type: 'success',
          });
          console.log(response.data.data)
          localStorage.setItem('user',JSON.stringify(response.data.data))
          const token = 'testToken123'
          Cookie.set('token', token)
          this.$router.push('/');
        } else {
          this.$message.error(response.data.msg);
        }
      }).catch(error => {
        // 请求失败处理
        console.error('登录请求失败:', error);
        this.$message.error('登录失败，请稍后重试!');
      });
    },
    handleSignup() {
      // 1. 获取用户输入的用户名和密码
      const username = this.$refs.username.value;
      const password = this.$refs.password.value;

      // 2. 发送注册请求
      console.log(username, password)
      alert(username, password)
      /*axios.post('/api/register', {
        username,
        password
      }).then((response) => {
        // 3. 注册成功
        if (response.data.code === 0) {
          // 提示注册成功
          this.$message.success('注册成功');

          // 跳转到登录页面
          this.$router.push('/login');
        } else {
          // 注册失败
          this.$message.error(response.data.message);
        }
      }).catch((error) => {
        // 注册失败
        this.$message.error('注册失败，请稍后再试');
      });*/
    }
  }
}
</script>
<style scoped lang="less">
.center {
  width: 100%;
  height: 100vh;
  background-image: url("../assets/Login.jpg");
  background-size: 100% 100%;
  background-repeat: no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  opacity: 0.75;
}

h1 {
  font-size: 30px;
  color: white;
}

.login {
  background-color: #fff;
  border-radius: 10px;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
  /* position: relative;
  overflow: hidden; */
  width: 768px;
  max-width: 100%;
  min-height: 480px;
  margin-top: 20px;
  display: flex;
  background: -webkit-linear-gradient(right, #4284db, #29eac4);
}

.overlaylong {
  border-radius: 10px 0 0 10px;
  width: 50%;
  height: 100%;
  background-color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.introduce {
  border-radius: 10px 0 0 10px;
  width: 70%;
  height: 100%;
  background-color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #b9c2e8;

}

.overlaylongleft {
  border-radius: 0px 10px 10px 0px;
  width: 50%;
  height: 100%;
  background-color: #fff;
  transform: translateX(100%);
  transition: transform 0.6s ease-in-out;
  display: flex;
  align-items: center;
  justify-content: center;
}

.overlaylongright {
  border-radius: 10px 0 0 10px;
  width: 50%;
  height: 100%;
  background-color: #fff;
  transform: translateX(0%);
  transition: transform 0.6s ease-in-out;
  display: flex;
  align-items: center;
  justify-content: center;
}

.overlaytitle {
  border-radius: 0px 10px 10px 0px;
  width: 50%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0);
  display: flex;
  align-items: center;
  justify-content: center;
}


.overlaytitleH2 {
  font-size: 30px;
  color: #fff;
  margin-top: 20px;
}

.overlaytitleP {
  font-size: 15px;
  color: #fff;
  margin-top: 20px;
}

.overlaytitleleft {
  border-radius: 0px 10px 10px 0px;
  width: 50%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0);
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translateX(0%);
  transition: transform 0.6s ease-in-out;
}

.overlaytitleright {
  border-radius: 0px 10px 10px 0px;
  width: 50%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0);
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translateX(-100%);
  transition: transform 0.6s ease-in-out;
}

.overlaytitle-Signin {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.overlaytitle-introduce {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.buttongohs {
  width: 180px;
  height: 40px;
  border-radius: 50px;
  border: 1px solid #fff;
  color: #fff;
  font-size: 15px;
  text-align: center;
  line-height: 40px;
  margin-top: 40px;
}

.overlaylongH2 {
  font-size: 25px;
  color: black;
  /* width: 250px; */
}

.overlaylong-Signin {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.overlaylong-introduce {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}


h3 {
  font-size: 10px;
  margin-top: 10px;
  cursor: pointer;
}

.inupbutton {
  background-color: #29eac4;
  border: none;
  width: 180px;
  height: 40px;
  border-radius: 50px;
  font-size: 15px;
  color: #fff;
  text-align: center;
  line-height: 40px;
  margin-top: 30px;
}
</style>
